package com.example.qxfw.config.doc;

import org.springframework.boot.system.ApplicationHome;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.FileOutputStream;

@RestController
@RequestMapping("/doc")
public class DocController {

    @GetMapping("/test")
    public void test() {
        ApplicationHome applicationHome = new ApplicationHome(this.getClass());
        String sourcePath = applicationHome.getDir().getParentFile().getParentFile().getAbsolutePath() + "/src/main/resources/templates/yjfwTemp/应急文档模板.docx";
        String targetPath = applicationHome.getDir().getParentFile().getParentFile().getAbsolutePath() + "\\src\\main\\resources\\temp\\test.docx";
        String imageFile = "C:\\Users\\路凯\\Desktop\\测试图片1.png";
        try(
                FileInputStream inputStream = new FileInputStream(sourcePath);
                FileOutputStream outputStream = new FileOutputStream((targetPath));
                CustomXWPFDocument document = new CustomXWPFDocument(inputStream);
                ){
            document.setCellImg(document,"[图片]",imageFile);
            document.write(outputStream);
        } catch (Exception e){
            e.printStackTrace();
        }

    }
}
